package com.usian.controller;

import com.usian.feign.ContentServiceFeign;
import com.usian.pojo.TbContentCategory;
import com.usian.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author lpf
 * @Date 2022/3/24 上午11:10
 * @ProjectName java134-e-commerce-project
 * @Version 1.0
 * @Description:
 */
@RestController
@RequestMapping(value = "backend/content")
public class ContentCategoryController {

    @Autowired
    private ContentServiceFeign contentServiceFeign;

    /**
     * 内容分类查询接口
     * @param id
     * @return
     * @Auth lpf
     */
    @RequestMapping(value = "selectContentCategoryByParentId")
    public Result selectContentCategoryByParentId(@RequestParam(defaultValue = "0") Long id){
        List<TbContentCategory> tbContentCategoryList = contentServiceFeign.selectContentCategoryByParentId(id);
        if (tbContentCategoryList != null && tbContentCategoryList.size() > 0){
            return Result.ok(tbContentCategoryList);
        }
        return Result.error("查询失败");
    }

    /**
     * 内容分类管理添加接口
     * @param tbContentCategory
     * @return
     * @Auth lpf
     */
    @RequestMapping(value = "insertContentCategory")
    public Result insertContentCategory(TbContentCategory tbContentCategory){
        Integer res = contentServiceFeign.insertContentCategory(tbContentCategory);
        if (res == 1){
            return Result.ok();
        }
        return Result.error("插入失败！");
    }


    /**
     * 根据id删除内容管理
     * @param categoryId
     * @return
     * @Auth fgg
     */
    @RequestMapping(value = "deleteContentCategoryById", method = RequestMethod.POST)
    public Result deleteContentCategoryById(Long categoryId) {
        Integer deleteContentCategoryById = contentServiceFeign.deleteContentCategoryById(categoryId);
        if (deleteContentCategoryById == 1){
            return Result.ok();
        }
        return Result.error("删除失败！");
    }
}
